#include "ParserData.h"
#include <iostream>
#include <iosfwd>
#include <fstream>

using namespace std;
ParserData::ParserData()
{
	m_ItemList.construct();
}

ParserData::~ParserData()
{
	memset(PrintChar,0x00,BUFFSIZE);
	memset(SourceChar,0x00,BUFFSIZE);
}

void ParserData::PrintData(const std::string& strQuery)
{
	size_t nSize(0);

	if (strQuery == "Property")
	{
		m_Property.unpack(SourceChar,BUFFSIZE);
		m_Property.visualize(PrintChar,BUFFSIZE,&nSize,0);
	}
	else if (strQuery == "Quest")
	{
		m_Quest.unpack(SourceChar,BUFFSIZE);
		m_Quest.visualize(PrintChar,BUFFSIZE,&nSize,0);
	}
	else if (strQuery == "ItemBag" || strQuery == "ItemStore" || strQuery == "ItemEquiped")
	{
		m_ItemList.unpack(SourceChar,BUFFSIZE);
		m_ItemList.visualize(PrintChar,BUFFSIZE,&nSize,0);
	}
	else if (strQuery == "Buff")
	{
		m_Buff.unpack(SourceChar,BUFFSIZE);
		m_Buff.visualize(PrintChar,BUFFSIZE,&nSize,0);
	}
	else if (strQuery == "SkillInfo")
	{
		m_SkillInfo.unpack(SourceChar,BUFFSIZE);
		m_SkillInfo.visualize(PrintChar,BUFFSIZE,&nSize,0);
	}
	else if (strQuery == "OtherInfo")
	{
		m_OtherInfo.unpack(SourceChar,BUFFSIZE);
		m_OtherInfo.visualize(PrintChar,BUFFSIZE,&nSize,0);	
	}
	//std::cout<<PrintChar;
	string outdir = strQuery + "_out.txt";
	ofstream fout(outdir.c_str());  //ios::binary
	fout.write(PrintChar,nSize);
	fout.close();
}




void ParserData::QueryData(const std::string& strQuery)//char* pChar,int nSize
{
	//ofstream fout("tdrtest.txt", ios::binary);
	//fout.write(pChar,nSize);
	//fout.close();

	ifstream fin(strQuery.c_str(), ios::binary);
	fin.read(SourceChar,BUFFSIZE);
};
